package com.cu.jiekong.frame;

import com.cu.jiekong.util.StringUtil;
import org.jboss.logging.NDC;
import org.slf4j.MDC;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author jintian
 * @date 2018/10/11 15:23
 */
@Configuration
@WebFilter
public class LogFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        MDC.clear();
        // 日志中放一个 key 便于日志查看
        MDC.put("key",StringUtil.UUIDStr());
        filterChain.doFilter(servletRequest,servletResponse);
        MDC.clear();
    }

    @Override
    public void destroy() {

    }
}
